﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class GirlFollowTag : MonoBehaviour
{
    NavMeshAgent navMeshAgent;
    /// <summary>
    /// 动画控制器
    /// </summary>
    Animator girlAnimator;

    float sumTime = 0;

    public GameObject foller;

    public UnityUWBClient client;
    // Start is called before the first frame update
    void Start()
    {
        navMeshAgent = GetComponent<NavMeshAgent>();
        girlAnimator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (client.isLogin)
        {
            sumTime += Time.deltaTime;
            if (sumTime > 0.5)
            {
                sumTime = 0;
                navMeshAgent.SetDestination(foller.transform.position);
            }
        }

        //return;
        //判断是否在移动
        if (navMeshAgent.velocity.sqrMagnitude == 0)
        {
            girlAnimator.SetBool("isWalking", false);
        }
        else
        {
            girlAnimator.SetBool("isWalking", true);
        }
    }
}
